﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;

namespace EzDesk.Apps.Model.Attendance
{
    /// <summary>
    /// 描述一天的考勤相关信息，包括节假日，公休等
    /// </summary>
    [DataContract] 
    public class DayInfo
    {
        #region [ Constructors ]
        public DayInfo()
            :this(DateTime.Now)
        {
        }

        public DayInfo(DateTime date)
        {
            Date = date;
        }

        #endregion

        #region [ Data Members ]
        /// <summary>
        /// 这天的日期
        /// </summary>
        [DataMember]
        public DateTime Date { get; set; }

        /// <summary>
        /// 这天属于的法定假日描述
        /// </summary>
        [DataMember]
        public LegalHoliday HolidayInfo { get; set; }

        /// <summary>
        /// 这天的轮休描述
        /// </summary>
        [DataMember]
        public ExtraShift ExtraShiftInfo { get; set; }

        #endregion

        private bool _isNeedToWork;
        private bool _isWeekEnd;


        /// <summary>
        /// 这天是否需要工作
        /// </summary>
        [DataMember]
        public bool IsNeedToWork
        {
            get
            {
                bool needToWork = true;
                if (IsWeekEnd || HolidayInfo != null)
                {
                    needToWork = false;
                }
                if (ExtraShiftInfo != null)
                {
                    needToWork = ExtraShiftInfo.IsNeedWork;
                }
                return needToWork;
            }
            set { _isNeedToWork = value; } /* just for serializeble*/
        }

        /// <summary>
        /// The day is Saturday or Sunday
        /// </summary>
        [DataMember]
        public bool IsWeekEnd
        {
            get
            {
                return Date.DayOfWeek == DayOfWeek.Saturday || Date.DayOfWeek == DayOfWeek.Sunday;
            }
            set
            {
                _isWeekEnd = value;  /* just for serializeble*/
            }
        }
    }
}
